package com.hd.core.project.module.controller;

import com.baomidou.mybatisplus.mapper.Condition;

import com.hd.core.common.utils.StringUtils;
import com.hd.core.project.module.base.WrapperBaseController;
import com.hd.core.project.module.config.TeacherModuleProperties;
import com.hd.core.project.module.domain.EduUploadDataTeacher;
import com.hd.core.project.module.service.EduUploadDataTeacherService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 教师工作报告<br/>
 * 教师查询每个月的工作情况<br/>
 * 
 * <br/>
 * @since JDK 1.8
 * @version  V1.0
 * @author RichardTang 
 * @date: 2018年9月7日
 * @package com.hd.core.project.module.controller
 * @copyright:Copyright (c) 2018, 1245811923@qq.com All Rights Reserved.
 */
@Controller
@SuppressWarnings("all")
@RequestMapping("/module/teacher/work-report")
public class WorkReportController extends WrapperBaseController<TeacherModuleProperties> {

    @Autowired
    private EduUploadDataTeacherService eduUploadDataTeacherService;

    WorkReportController() {
        super("/work-report");
    }

    /**
     * 跳转到工作报告视图
     * 
     * @return 跳转视图
     */
    @GetMapping
    @RequiresPermissions("module-teacher:work-report:view")
    public String view(){
        return getResponseViewPath("/work-report");
    }

    /**
     * 根据条件查询工作报告的数据
     * 
     * @param date 对应的日期 默认查询当前月份
     * @return 跳转视图
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions("module-teacher:work-report:list")
    public EduUploadDataTeacher list(String date){
        String[] dateSplit = null;
        Condition condition = new Condition();
        if(StringUtils.isEmpty(date)){
            date = new SimpleDateFormat("yyyy-MM").format(new Date());
        }
        dateSplit = date.split("-");
        condition.eq("year",dateSplit[0]);
        condition.eq("month",dateSplit[1]);
        condition.eq("name",getUser().getUserName());
        EduUploadDataTeacher eduUploadDataTeacher = eduUploadDataTeacherService.selectOne(condition);
        return eduUploadDataTeacher;
    }
}

